package com.xinhe.web.controller;

import com.querydsl.core.QueryResults;
import com.xinhe.web.common.Result;
import com.xinhe.web.entity.OrderItem;
import com.xinhe.web.request.OrderItemModel;
import com.xinhe.web.service.OrderItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Set;

@Api(value = "商品订单项", tags = {"商品订单项"})
@RestController
@RequestMapping(value = {"/orderItem"}, produces = {"application/json;charset=UTF-8"})

public class OrderItemController {
    @Autowired
    private OrderItemService orderItemService;

    @ApiOperation(httpMethod = "GET", value = "分页查询商品订单项")
    @RequestMapping({"/pageOrderItem"})
    public QueryResults<OrderItem> pageOrderItem(int pageNum, int pageSize) {
        return this.orderItemService.pageOrderItem(pageNum, pageSize);
    }

    @ApiOperation(httpMethod = "POST", value = "保存商品订单项")
    @RequestMapping({"/saveOrderItem"})
    public Result saveOrderItem(@Valid OrderItemModel model) {
        return this.orderItemService.saveModel(model);
    }

    @ApiOperation(httpMethod = "GET", value = "删除商品订单项")
    @ApiImplicitParam(name = "orderItemId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/deleteOrderItem"})
    public Result deleteOrderItem(Long orderItemId) {
        return this.orderItemService.delete(orderItemId);
    }

    @ApiOperation(httpMethod = "GET", value = "商品订单项详情")
    @ApiImplicitParam(name = "orderItemId", value = "标识", dataTypeClass = Long.class, required = true)
    @RequestMapping({"/detailOrderItem"})
    public Result<OrderItem> detailOrderItem(Long orderItemId) {
        return this.orderItemService.findById(orderItemId);
    }

    @ApiOperation("根据订单项id查询订单")
    @RequestMapping({"/findByOrderItem"})
    public Result findByOrderItem(Set<Long> orderItemIds) {
        return this.orderItemService.findByOrderItem(orderItemIds);
    }

}
